package com.yiyuan.common.util;

import java.io.IOException;
import java.sql.SQLException;
import org.springframework.dao.DataAccessException;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.yiyuan.common.exception.SystemException;

public class ExceptionInterceptor extends AbstractInterceptor {
	private static final long serialVersionUID = 1L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		String result = "";
		try {
			result = invocation.invoke();
		} catch (DataAccessException ex) {
			throw new SystemException("数据库操作失败，");
		} catch (NullPointerException ex) {
			throw new SystemException("调用了未经初始化的对象或者是不存在的对象，");
		} catch (IOException ex) {
			throw new SystemException("IO异常，");
		} catch (ClassNotFoundException ex) {
			throw new SystemException("指定的类不存在，");
		} catch (ArithmeticException ex) {
			throw new SystemException("数学运算异常，");
		} catch (ArrayIndexOutOfBoundsException ex) {
			throw new SystemException("数组下标越界，");
		} catch (IllegalArgumentException ex) {
			throw new SystemException("方法的参数错误，");
		} catch (ClassCastException ex) {
			throw new SystemException("类型强制转换错误，");
		} catch (SecurityException ex) {
			throw new SystemException("违背安全原则异常，");
		} catch (SQLException ex) {
			throw new SystemException("操作数据库异常，");
		} catch (NoSuchMethodError ex) {
			throw new SystemException("方法末找到异常，");
		} catch (InternalError ex) {
			throw new SystemException("Java虚拟机发生了内部错误，");
		} catch (Exception ex) {
			throw new SystemException("程序内部错误，操作失败，");
		}
		return result;
	}
}
